package com.ly.drivingschool.service.impl;

import com.ly.drivingschool.dao.TweetDao;
import com.ly.drivingschool.pojo.Pager;
import com.ly.drivingschool.pojo.Setmeal;
import com.ly.drivingschool.pojo.Tweet;
import com.ly.drivingschool.service.TweetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class TweeServiceImpl implements TweetService {
    @Autowired
    private TweetDao tweetDao;
    /**
     * 添加一个订阅
     * @param record
     * @return
     */
    @Override
    public int insertSelective(Tweet record) {
        int code = tweetDao.insertSelective(record);
        return code;
    }

    /**
     * 根据id删除一条记录
     * @param tweet_id
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer tweet_id) {
        int code = tweetDao.deleteByPrimaryKey(tweet_id);
        return code;
    }

    /**
     * 查询一条记录
     * @param tweet_id
     * @return
     */
    @Override
    public Tweet selectByPrimaryKey(Integer tweet_id) {
        Tweet tweet = tweetDao.selectByPrimaryKey(tweet_id);
        return tweet;
    }

    /**
     * 分页查询
     * @return
     */
    @Override
    public Pager<Tweet> findByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        Pager<Tweet> pager = new Pager<Tweet>();
        List<Tweet> list = tweetDao.findByPager(params);
        pager.setData(list);
        pager.setCount(tweetDao.count());
        return pager;
    }

    /**
     * 模糊查询分页
     * @param page
     * @param size
     * @param keyWork
     * @return
     */
    @Override
    public Pager<Tweet> findByKey(int page, int size, String keyWork) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        params.put("keyWork", keyWork);
        Pager<Tweet> pager = new Pager<Tweet>();
        List<Tweet> list = tweetDao.findByKey(params);
        pager.setData(list);
        pager.setCount(tweetDao.countKey(keyWork));
        return pager;
    }

    @Override
    public long count() {
        return 0;
    }

    @Override
    public long countKey(String keyWork) {
        return 0;
    }
}
